package com.xm.zcf.dao.order;

import com.sun.org.apache.xpath.internal.operations.Or;
import com.xm.zcf.action.Base.SessionBase;
import com.xm.zcf.domain.order.Orders;
import com.xm.zcf.domain.product.Product;
import com.xm.zcf.util.PageBean;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Administrator on 2017/4/12.
 */
@Repository
public class OrderDaoImpl extends SessionBase implements OrderDao {
    @Override
    public void save(Orders model) {
        getSession().save(model);
    }

    @Override
    public PageBean findByUid(Integer page, Integer limit, int uid) {
        List<Product> list=getSession().createQuery("from Orders o where o.adminuser.uid=? order by  o.ordertime desc")
                .setParameter(0,uid)
                .setFirstResult((page-1)*limit)
                .setMaxResults(limit)
                .list();
        Long count=(Long)getSession().createQuery("select count(*) from Orders o where o.adminuser.uid=?")
                .setParameter(0,uid)
                .uniqueResult();
        return new PageBean<Product>(page,limit,count.intValue(),list);
    }

    @Override
    public Orders findByOid(String oid) {
        return (Orders)getSession().createQuery("from Orders o where oid=?").setParameter(0,oid).uniqueResult();
    }

    @Override
    public void update(Orders orders) {
        getSession().update(orders);
    }
}
